package com.easyOrder.service.user;

import com.easyOrder.dao.UserBranchMapper;
import com.easyOrder.model.UserBranch;
import com.easyOrder.model.UserBranchExample;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by liutao on 2017/8/4.
 */
@Service
public class UserBranchService {

    @Autowired
    private UserBranchMapper userBranchMapper;

    public UserBranch findByUserId(Long userId, Boolean isSuperUser) {
        UserBranchExample example = new UserBranchExample();
        UserBranchExample.Criteria criteria = example.createCriteria();
        criteria.andUserIdEqualTo(userId);
        if (isSuperUser != null) {
            criteria.andIsSuperUserEqualTo(isSuperUser ? 1 : 0);
        }
        List<UserBranch> userBranches = userBranchMapper.selectByExample(example);
        if(CollectionUtils.isNotEmpty(userBranches)){
            return userBranches.get(0);
        }
        return null;
    }

}
